/**
 * 
 */
package edu.ucmo.cis.enrollment.backaction;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.googlecode.jsonplugin.annotations.JSON;
import org.apache.struts2.ServletActionContext;
import edu.ucmo.cis.enrollment.service.SystemAdminService;
import edu.ucmo.cis.enrollment.vo.SystemAdmin;
import edu.ucmo.cis.util.GlobalDefination;

import com.opensymphony.xwork2.ActionSupport;
/**
 * @author Jiang
 * Email:sjiangmo@gmail.com
 */
public class SystemAdminLoginAction extends ActionSupport{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private String loginName;				
	private String password;	
	Map<String, Object> result;
	private SystemAdminService systemAdminService;
	private SystemAdmin systemAdmin;
	private Map<String, Object> session;
	
	@JSON(serialize=false)
	public Map<String, Object> getSession() {
		return session;
	}

	public void setSession(Map<String, Object> session) {
		this.session = session;
	}

	public Map<String, Object> getResult() {
		return result;
	}

	public void setResult(Map<String, Object> result) {
		this.result = result;
	}

	public String getLoginName() {
		return loginName;
	}

	public void setLoginName(String loginName) {
		this.loginName = loginName;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public SystemAdminService getSystemAdminService() {
		return systemAdminService;
	}

	public void setSystemAdminService(SystemAdminService systemAdminService) {
		this.systemAdminService = systemAdminService;
	}

	public SystemAdmin getSystemAdmin() {
		return systemAdmin;
	}

	public void setSystemAdmin(SystemAdmin systemAdmin) {
		this.systemAdmin = systemAdmin;
	}

	@Override
	public String execute() throws Exception {
		System.out.println("execute~~~~");
		return SUCCESS;
	}
	
	public String login() {
		result = new HashMap<String, Object>();
		try {
			SystemAdmin s=systemAdminService.searchByLoginName(loginName);
			if(s!=null){
				if(s.getPassword().equals(password)){
					getSession().put(GlobalDefination.MEMBER, s);
					result.put("success", true);
					result.put("msg", "");
					
				}else{
					result.put("success", false);
					result.put("msg","2");
				}
				
			}else{
				result.put("success", false);
				result.put("msg", "1");
			}			
		} catch (Exception e) {
			e.printStackTrace();
		}
		return "data";
	}

}
